import os
from nlp_tools.corpus.classify.competition import DataFoundClassify




data_path = r'/home/qiufengfeng/nlp/competition/datagrand/基于大规模预训练模型的风险事件标签识别/processed'
token_path = os.path.join(data_path,'vocab.txt')


train_data = r"/home/qiufengfeng/nlp/competition/datagrand/基于大规模预训练模型的风险事件标签识别/datagrand_2021_train.csv"
test_data = r"/home/qiufengfeng/nlp/competition/datagrand/基于大规模预训练模型的风险事件标签识别/datagrand_2021_test.csv"



submit_path = r"./submissioin.csv"
model_save_path = './tf_models'


use_network_type = "dpcnn"

save_endfix = ""

fianl_model_save_path = os.path.join(model_save_path,use_network_type+save_endfix)
#####
#数据加载器类
data_loader_class = DataFoundClassify



from nlp_tools.processors.sequence_processor import SequenceProcessor
from nlp_tools.processors.classification.classification_label_processor import ClassificationLabelProcessor


from nlp_tools.tokenizer.whitespace_tokenizer import WhiteSpaceTokenizer
from nlp_tools.embeddings.bare_embedding import BareEmbedding


from nlp_tools.tasks.classification.dpcnn_model import DPCNN_Model

from nlp_tools.generators import BatchGenerator

network_configs = {
    'dpcnn':{
        "Tokenizer":{
                    'class':WhiteSpaceTokenizer,
                    'params':{"token_dict":token_path}
        },

        "Embedding":{
            'class':BareEmbedding,
            'params':{
                        "embedding_size":256,
                        "max_sentence_len":400
                    }
        },

        "SentenceProcessor":{
            "class":SequenceProcessor,
            "params":{
            }
        },

        "LabelProcessor": {
            'class':ClassificationLabelProcessor,
            'params':{}
        },

        "Network":{
            'class':DPCNN_Model,
            'params':{
                "max_sequence_length":400,
                "train_sequece_length_as_max_sequence_length":400
            }
        }
    }
}

train_params = {
    'data_loader':DataFoundClassify,
    'train_data':train_data,

    'model_save_path':model_save_path,
    'fit_params':{
        'epochs':30,
        'batch_size':128,
        'generator':BatchGenerator
    }
}



def init_class(class_info):
    class_type = class_info['class']
    class_params = class_info['params']
    return class_type(**class_params)

def init_object(config_dict,object_name,object_params_init=None):
    if object_name not in config_dict:
        raise ValueError("传入的参数有问题")

    object_dict = config_dict[object_name]
    if 'class' not in object_dict:
        raise ValueError("传入的参数有问题")
    object_class = object_dict['class']

    object_params = {}
    if 'params' in object_dict:
        object_params = object_dict['params']

    if  object_params_init:

        object_params.update(object_params_init)

    for key,value in object_params.items():
        if type(value) == dict:
            object_params[key] = init_class(value)


    return object_class(**object_params)




